<template>
  <Content title="确认">
    <view class="quality-confirmation-box">
      <u-form
        labelPosition="top"
        :model="model"
        labelWidth="200"
        labelAlign="left"
        :rules="rules"
        ref="uForm"
      >
        <u-form-item
          :label="type === '1' ? '是否自行维修完成' : '是否现场维修完成'"
          prop="boardingDate"
          labelPosition="top"
          required
        >
          <u-radio-group
            style="margin-top: 5px"
            v-model="model.isRepairMyself"
            placement="row"
          >
            <u-radio label="是" :name="1" style="margin-right: 20px"></u-radio>
            <u-radio label="否" :name="0"></u-radio>
          </u-radio-group>
        </u-form-item>

        <template v-if="type === '1'">
          <u-form-item
            label="拆模类型："
            prop="demoldingType"
            required
            v-if="model.isRepairMyself == 0"
          >
            <uni-data-select
              v-model="model.demoldingType"
              :localdata="demoList"
              placeholder="请填写拆模类型"
            ></uni-data-select>
          </u-form-item>
          <u-form-item label="维修方法" prop="repairWay" required v-else>
            <u-input
              label
              v-model="model.repairWay"
              placeholder="请填写"
              clearable
            ></u-input>
          </u-form-item>
        </template>
        <template v-else>
          <u-form-item
            label="模具异常情况描述"
            prop="moldExceptionDesc"
            v-if="model.isRepairMyself == 0"
            required
          >
            <u-textarea
              style="margin-top: 20px"
              v-model="model.moldExceptionDesc"
              placeholder="请填写"
            ></u-textarea>
          </u-form-item>
          <u-form-item label="维修方法" prop="repairWay" required v-else>
            <u-input
              label
              v-model="model.repairWay"
              placeholder="请填写"
              clearable
            ></u-input>
          </u-form-item>
        </template>

        <view class="btn-v">
          <view class="but-box">
            <u-button class="btn" @click="close" text="取消"></u-button>
            <u-button
              class="btn"
              type="primary"
              @click="submit"
              text="确定"
            ></u-button>
          </view>
        </view>
      </u-form>
    </view>
  </Content>
</template>

<script>
import Content from "@/components/content/index.vue";
import { getPageData } from "@/store/user";
import fetch from "@/utils/fetch";
export default {
  components: {
    Content,
  },
  data() {
    return {
      id: "",
      model: {
        isRepairMyself: 1,
        demoldingType: "",
        repairWay: "",
      },
      obj: {},
      rules: {
        demoldingType: {
          required: true,
          message: "请选择",
          trigger: ["blur", "change"],
        },
        moldExceptionDesc: {
          required: true,
          message: "请填写",
          trigger: ["blur", "change"],
        },
        repairWay: {
          required: true,
          message: "请填写",
          trigger: ["blur", "change"],
        },
      },
      radioValue: "",
      demoList: [
        { text: "试模NG", value: "1" },
        { text: "异常发生", value: "2" },
        { text: "冲次满保养", value: "3" },
        { text: "生产需要且完成任务", value: "4" },
      ],
      type: "1",
    };
  },
  onLoad: function (option) {
    //option为object类型，会序列化上个页面传递的参数
    this.obj = getPageData();
    this.type = option.type || "1";
  },
  onShow: function () {},
  mounted() {},
  methods: {
    close() {
      uni.navigateBack({
        delta: 1,
      });
    },
    submit() {
      let url;
      const that = this;
      if (that.obj.maintenanceStatus == "1") {
        url = "/dms/moldMaintenanceHall/productConfirm";
      } else if (that.obj.maintenanceStatus == "2") {
        url = "/dms/moldMaintenanceHall/repairConfirm";
      }
      this.$refs.uForm.validate().then((valid) => {
        if (valid) {
          that.$loading.open();
          fetch("post", url, {
            ...this.model,
            id: this.obj.id,
          }).then((res) => {
            if (res.code === 200) {
              uni.$emit("openToast", {
                type: "success",
                title: res.msg,
                complete() {
                  uni.navigateBack({
                    delta: 1,
                  });
                },
              });
            } else {
            }
          });
        }
      });
    },
  },
};
</script>

<style scoped lang="scss">
.quality-confirmation-box {
  padding: 40rpx;
  background-color: #fff;
  min-height: 100%;
}
</style>
